-- 奖励 panel

local GuildWarAwardTabPanel = app.mvc.createPanelClass(...)
local ListViewVertical = require("app.widget.listview.ListViewVertical")
local GuildWarAward1Cell = import("..renders.GuildWarAward1Cell")
local GuildWarAward2Cell = import("..renders.GuildWarAward2Cell")
local GuildWarAward3Cell = import("..renders.GuildWarAward3Cell")
local CrossServerGuildWarHelper = require("app.crossServer.views.guildWar.CrossServerGuildWarHelper")

function GuildWarAwardTabPanel.createWithData(data, node)
    local sprite = GuildWarAwardTabPanel.extend(node)
    if node == nil then
        ccui.Helper:doLayout(sprite)
    end
    sprite:init(data)
    return sprite
end

function GuildWarAwardTabPanel.create(node)
    return GuildWarAwardTabPanel.createWithData(nil, node)
end

function GuildWarAwardTabPanel:init(data)
    self.super.init(self, data)
    local params = {
        cellConfigs = {
            [1] = {renderClass = GuildWarAward1Cell, perNum = 1},
            [2] = {renderClass = GuildWarAward2Cell, perNum = 1},
            [3] = {renderClass = GuildWarAward3Cell, perNum = 2},
        },
        cellTagMarkFunc = function(data)
            if data.minRank == 1 then
                return 1
            elseif data.minRank <= 3 then
                return 2
            else
                return 3
            end
        end,
        cellEventProxy = function(eventName, rank)
			app:sendMsg("CrossServerController", "popGuildWarMemberAward", rank)
		end,
    }
    self._listView = ListViewVertical.new(self, params)
    self:registerViewEvent({
        {name = ViewEvent.CSGuildWar_SeasonRank, callback = handler(self, self._onSeasonRank)},
       
    })

    self._awardsData = CrossServerGuildWarHelper.getGuildsRankAward()
    self:refresh()
end


function GuildWarAwardTabPanel:_onSeasonRank(eventName, datas, curSeason)
    local guilds = {} 
    if datas then
        guilds = datas.guilds or {}
    end
    for k, v in pairs( self._awardsData) do
        v.guildData = guilds[v.minRank]
    end
    self:refresh()
end

function GuildWarAwardTabPanel:onTabSelect()
    UD.csGuildWarData:reqLastSeaonRankData()
end

function GuildWarAwardTabPanel:refresh()
    self._listView:reloadData(self._awardsData)
end

function GuildWarAwardTabPanel:setPanelTabIndex(index)
    self._tabPanelIndex = index
end

-- -- 测试数据代码
-- function GuildWarAwardTabPanel:getTestData()
--     local data = {}
--     for i = 1, 10 do
--         table.insert( data, {rank = i})
--     end
--     return data
-- end


return GuildWarAwardTabPanel